package LeetCode;

import java.util.Arrays;

public class LeetCodeMain9 {
    public int majorityElement(int[] nums) {
        Arrays.sort(nums);
        return nums[nums.length/2];
    }
    public static int repeatedStringMatch(String a, String b) {
        boolean[] booleans=new boolean[26];
        for (Character ch:a.toCharArray()) {
            booleans[ch-'a']=true;
        }
        for (Character ch:b.toCharArray()) {
            if (!booleans[ch-'a']){
                return -1;
            }
        }
        StringBuilder str=new StringBuilder();
        int k=b.length()/a.length();
        str.append(a.repeat(k));
        for (int i = 0; i < 3; i++) {
            if (str.toString().contains(b)){
                return k+i;
            }
            str.append(a);
        }
        return -1;
    }
    public static void main(String[] args) {
        System.out.println(repeatedStringMatch("d","abcd"));
    }
}
